<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class Member extends Model
{
//    protected $fillable = [
//        'name','phone','openid','address','hospital','section','status'
//    ];
    protected $guarded = [];
    protected $casts = [
        'status' => 'boolean'
    ];

    protected static function boot()
    {
        parent::boot();

        static::updating(function($member){
            if ($member->status){
                self::setAcceptedAt($member);
            }
        });
    }

    protected static function setAcceptedAt($member){
        DB::table('members')->where('id', $member->id)->update([
            'accepted_at' => Date('Y-m-d H:i:s', time())
        ]);
    }
}
